import Vue from "vue";
import Router from "vue-router";
import Layout from '@/layout/index'
import i18n from '@/locale/index'
// 权限管理
import authority from './module/authority'
// 系统管理
import system from "./module/system";
// 租户管理
import tenant from "./module/tenant";
// 订单管理
import order from "./module/order";
// 产品管理
import product from "./module/product";
// 用户管理
import user from "./module/user";
// 财务管理
import finance from "./module/finance";
// 贷后管理
import loanService from "./module/loanService";
// 资金管理
import capital from "./module/capital";
// 提醒管理
import remind from "./module/remind";
// 报表管理
import report from "./module/report";
// 渠道管理
import channel from "./module/channel"
// 营销管理
import marketing from "./module/marketing";
// 优惠券管理
import coupon from "./module/coupon";

Vue.use(Router)
/**
 * @meta.path 匹配后台路径动态渲染路由
 * @isHideSidebar 是否隐藏侧边栏
 */
export const asyncRoutes = [
    {
        path: '/homePage',
        redirect: '/homePage/index',
        meta: {
            path: 'homePage/index'
        },
        component: Layout,
        children: [
            {
                path: 'index',
                name: 'homePage',
                meta: {
                    path: 'homePage/index'
                },
                component: () => import('@/views/homePage/index'),
            }
        ]
    },
    authority,
    system,
    tenant,
    order,
    product,
    user,
    finance,
    loanService,
    capital,
    remind,
    report,
    channel,
    marketing,
    coupon
]
const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        component: () => import('@/compoents/login')
    },
    {
        path: '/404',
        component: () => import('@/compoents/404/index')
    },

]
const createRouter = () => new Router({
    scrollBehavior: () => ({y: 0}),
    mode: 'history',
    routes: routes
})
const router = createRouter()

export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
